import { BasicColumn } from '/@/components/Table';
import { FormSchema } from '/@/components/Table';
import { rules } from '/@/utils/helper/validator';
import { render } from '/@/utils/common/renderUtils';
import { getWeekMonthQuarterYear } from '/@/utils';
import { regionData } from '@/components/Form/src/utils/areaDataUtil';
//列表数据
export const columns: BasicColumn[] = [
  {
    title: '省编码',
    align: 'center',
    dataIndex: 'provinceCode',
    customRender({ record }) {
      for (let i = 0; i < regionData.length; i++) {
        const item = regionData[i];
        if (item.value == record.provinceCode) {
          return item.label;
        }
      }
    },
  },
  {
    title: '市编码',
    align: 'center',
    dataIndex: 'cityCode',
    customRender({ record }) {
      for (let i = 0; i < regionData.length; i++) {
        const item = regionData[i];
        if (item.value == record.provinceCode) {
          for (let j = 0; j < item.children.length; j++) {
            const cityCode = item.children[j].value;
            if (cityCode == record.cityCode) {
              return item.children[j].label;
            }
          }
        }
      }
    },
  },
  {
    title: '区编码',
    align: 'center',
    dataIndex: 'countyCode',
    customRender({ record }) {
      for (let i = 0; i < regionData.length; i++) {
        const item = regionData[i];
        if (item.value == record.provinceCode) {
          for (let j = 0; j < item.children.length; j++) {
            const cityCode = item.children[j].value;
            if (cityCode == record.cityCode) {
              for (let k = 0; k < item.children[j].children.length; k++) {
                const countyCode = item.children[j].children[k].value;
                if (countyCode == record.countyCode) {
                  return item.children[j].children[k].label;
                }
              }
            }
          }
        }
      }
    },
  },
  {
    title: '详细地址',
    align: 'center',
    dataIndex: 'detailAddress',
  },
  {
    title: '提货点名称',
    align: 'center',
    dataIndex: 'name',
  },
  {
    title: '联系人',
    align: 'center',
    dataIndex: 'associates',
  },
  {
    title: '联系电话',
    align: 'center',
    dataIndex: 'mobile',
  },
  {
    title: '供应商',
    align: 'center',
    dataIndex: 'supplierId_dictText',
  },
];
//查询数据
export const searchFormSchema: FormSchema[] = [
  {
    label: '提货点名称',
    field: 'name',
    component: 'JInput',
  },
  {
    label: '联系人',
    field: 'associates',
    component: 'JInput',
  },
  {
    label: '联系电话',
    field: 'mobile',
    component: 'JInput',
  },
];
//表单数据
export const formSchema: FormSchema[] = [
  {
    label: '位置',
    field: 'position',
    component: 'JAreaSelect',
    required: true,
  },
  {
    label: '详细地址',
    field: 'detailAddress',
    component: 'Input',
    required: true,
  },
  {
    label: '提货点名称',
    field: 'name',
    component: 'Input',
    required: true,
  },
  {
    label: '联系人',
    field: 'associates',
    component: 'Input',
    required: true,
  },
  {
    label: '联系电话',
    field: 'mobile',
    component: 'Input',
    required: true,
  },
  // TODO 主键隐藏字段，目前写死为ID
  {
    label: '',
    field: 'id',
    component: 'Input',
    show: false,
  },
];

// 高级查询数据
export const superQuerySchema = {
  provinceCode: { title: '省编码', order: 1, view: 'text', type: 'string' },
  cityCode: { title: '市编码', order: 2, view: 'text', type: 'string' },
  countyCode: { title: '区编码', order: 3, view: 'text', type: 'string' },
  detailAddress: { title: '详细地址', order: 4, view: 'text', type: 'string' },
  name: { title: '提货点名称', order: 5, view: 'text', type: 'string' },
  associates: { title: '联系人', order: 6, view: 'text', type: 'string' },
  mobile: { title: '联系电话', order: 7, view: 'text', type: 'string' },
  supplierId: { title: '供应商标识', order: 8, view: 'text', type: 'string' },
};

/**
 * 流程表单调用这个方法获取formSchema
 * @param param
 */
export function getBpmFormSchema(_formData): FormSchema[] {
  // 默认和原始表单保持一致 如果流程中配置了权限数据，这里需要单独处理formSchema
  return formSchema;
}
